<?php


namespace app\dao\exam;


use app\dao\BaseDao;
use app\model\exam\ExamQuestion;
use app\model\exam\ExamQuestionImg;

class ExamQuestionImgDao extends BaseDao
{


    protected function setModel(): string
    {
        return ExamQuestionImg::class;
    }

    //----------------------------------------------------api-------------------------------------------------------
    /*
     * 判断是否已经保存
     */
    public function isCunzai(array $where){
        return $this->search()
            ->where('user_id',$where['user_id'])
            ->where('exam_id',$where['exam_id'])
            ->where('question_id',$where['question_id'])
            ->withoutField(['create_time','delete_time'])
            ->find();

    }

    /*
     * 保存上传的题目图片
     */
    public function createImg(array $where){
        return $this->search()
            ->insert($where);
    }
    /*
     * 更新上传的图片
     */
    public function updateImg(array $where){
        return $this->search()
            ->where('user_id',$where['user_id'])
            ->where('exam_id',$where['exam_id'])
            ->where('question_id',$where['question_id'])
            ->update($where);
    }

    public function getQuestion(array $where)
    {
        return (new ExamQuestion()) ->field('title') ->  find($where['question_id']);
    }
}